package com.gong.springmvc;

import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController {
    @RequestMapping(value = "/hello", method = RequestMethod.GET, produces = "application/json")
    public String say() {
        return "Hello World";
    }

    @RequestMapping("/r1")
    public String r1(Integer age){
        return "接收到参数" + age;
    }

    @RequestMapping("/r2")
    public String r2(int age){
        return "接收到参数" + age;
    }


    //传递对象时
    @RequestMapping("/r3")
    public String r3(Student student){
        return student.toString();
    }

    @RequestMapping("/r4")
    public String r4(@RequestParam(value = "name" , required = false) String userName){
        return "接收到参数" + userName;
    }


    //数组传参
    @RequestMapping("/r5")
    public String r5(String[] array){
        return "接收到参数" + Arrays.toString(array);
    }

    //接收list
    @RequestMapping("/r6")
    public String r6(@RequestParam List<String> list){
        return "接收到参数" + list;
    }


    //接收json
    @RequestMapping("/r7")
    public String r7(Student student){
        return student.toString();
    }

    @RequestMapping("r8")
    public String r8(@RequestBody Student student){
        return student.toString();
    }
}
